package com.example.demo.common.http;

public class RestResult<T> {
    private String code;
    private String msg;
    private T data;

    public RestResult() {

    }
    public RestResult(ErrorCode errorCode) {
        this(errorCode, null);
    }

    public RestResult(ErrorCode errorCode, T data) {
        this.code = errorCode.getCode();
        this.msg = errorCode.getMsg();
        this.data = data;
    }

    public static <T> RestResult<T> getSuccessResult() {
        return new RestResult<T>(RestCode.SUCCESS);
    }

    public static <T> RestResult<T> getSuccessResult(T data) {
        return new RestResult<T>(RestCode.SUCCESS, data);
    }

    public static <T> RestResult<T> getFailResult() {
        return new RestResult<T>(RestCode.FAIL);
    }

    public static <T> RestResult<T> getFailResult(ErrorCode errorCode) {
        return new RestResult<T>(errorCode);
    }

    public String getCode() {
        return code;
    }

    public RestResult<T> setCode(String code) {
        this.code = code;
        return this;
    }

    public String getMsg() {
        return msg;
    }

    public RestResult<T> setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public T getData() {
        return data;
    }

    public RestResult<T> setData(T data) {
        this.data = data;
        return this;
    }

}
